package com.george.payment.wechat.controller;

import com.george.common.entity.dto.Result;
import com.george.common.entity.vo.payment.MallWeixinPayReq;
import com.george.payment.wechat.service.WeixinPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @title: WeixinPayController.java
 * @description: 微信支付接口
 * @author: George
 * @date: 2023/6/25 14:56
 */
@Slf4j
@RestController
@RequestMapping("/payment/wechat")
public class WeixinPayController {

    @Resource
    private WeixinPayService weixinPayService;


    /**
     * 微信扫码支付：调用微信统一下单接口，生成付款二维码
     *
     * @param payParam
     * @return com.george.common.entity.dto.Result
     * @author George
     * @date 2023/6/25 16:55
     */
    @PostMapping("/nativePay")
    public Result nativePay(@RequestBody @Valid MallWeixinPayReq payParam) {
        return weixinPayService.nativePay(payParam);
    }


    /**
     * 微信JSAPI下单：商户系统先调用该接口在微信支付服务后台生成预支付交易单，返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。
     *
     * @param payParam
     * @return com.george.common.entity.dto.Result
     * @author George
     * @date 2023/6/26 14:55
     */
    @PostMapping("/jsapiPay")
    public Result jsapiPay(@RequestBody @Valid MallWeixinPayReq payParam) {
        return weixinPayService.jsapiPay(payParam);
    }

    /**
     * 用户微信支付成功后，回调通知接口(提供给微信调用)
     *
     * @param request
     * @return com.george.common.entity.dto.Result
     * @author George
     * @date 2023/6/25 17:40
     */
    @PostMapping("/notify")
    public Result notify(HttpServletRequest request) {
        return weixinPayService.notify(request);
    }

    /**
     * 微信支付订单结果查询
     *
     * @param payReq
     * @return com.george.common.entity.dto.Result
     * @author George
     * @date 2023/6/26 16:02
     */
    @PostMapping("/wechatPayOrderQuery")
    public Result wechatPayOrderQuery(@RequestBody @Valid MallWeixinPayReq payReq) {
        return weixinPayService.wechatPayOrderQuery(payReq);
    }
}
